package co.fitstart.entity.reference;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;

import com.alibaba.fastjson.annotation.JSONField;
import com.demo2do.core.format.PersistentFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
 * @author Leo
 */
@Entity
@Table(name = "geo")
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
@PersistentFormat(key = String.class)
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class Geo {

    public final static String All_CITY = "0";

    @Id
    @GenericGenerator(name = "generator", strategy = "assigned")
    @GeneratedValue(generator = "generator")
    private String code;

    @Enumerated(EnumType.ORDINAL)
    private Level level;

    private String belongs;

    private String name;
    
    private String alias;
    
    private int display;
    
    /**
     * The default constructor
     */
    public Geo() {

    }

    /**
     * 
     * @param code
     * @param name
     * @param belongs
     * @param level
     */
    public Geo(String code, String name, String belongs, Level level) {
        this.code = code;
        this.name = name;
        this.belongs = belongs;
        this.level = level;
    }

    /**
     * 
     * @return
     */
    @Transient
    @JSONField(serialize = false)
    public boolean isCity() {
        return this.level.equals(Level.CITY);
    }
    
    /**
     * @return the code
     */
    public String getCode() {
        return code;
    }

    /**
     * @return the level
     */
    public Level getLevel() {
        return level;
    }

    /**
     * @return the belongs
     */
    public String getBelongs() {
        return belongs;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }
    
    /**
     * @return the alias
     */
    public String getAlias() {
        return this.alias;
    }
    
    /**
     * @return the display
     */
    public int getDisplay() {
        return this.display;
    }
    
    /**
     * @param code
     *            the code to set
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * @param level
     *            the level to set
     */
    public void setLevel(Level level) {
        this.level = level;
    }

    /**
     * @param belongs
     *            the belongs to set
     */
    public void setBelongs(String belongs) {
        this.belongs = belongs;
    }

    /**
     * @param name
     *            the name to set
     */
    public void setName(String name) {
        this.name = name;
    }
    
    /**
     * @param alias the alias to set
     */
    public void setAlias(String alias) {
        this.alias = alias;
    }
    
    /**
     * @param display the display to set
     */
    public void setDisplay(int display) {
        this.display = display;
    }
    
    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    public String toString() {
        return this.code + "|" + this.name;
    }

}
